package org.huntaway.kernel.filemg;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class FileCommon {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String rootStr = "D:";
		try {
			File[] files=(new File(rootStr)).listFiles();
			for (File file : files) {
				System.out.println(file.getName() + "\t\t" + file.canRead());
			}
			File file = new File(//rootStr,
					"d:\\sapp_web.rar");
			Class clazz = file.getClass();
			Field[] fields = clazz.getDeclaredFields();
			Field.setAccessible(fields, false);
			for (Field field : clazz.getDeclaredFields()) {
				field.setAccessible(true);
				System.out.println(field.getName() + "\t\t" + field.get(file));
			}
			System.out.println("-------------------------");
			Method[] methods = clazz.getDeclaredMethods();
			Method.setAccessible(methods, true);
			for (Method method : methods) {
				System.out.println(method.getName() + "\t\t"
						+ getValu(file, method));
			}
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	private static Object getValu(File file, Method method)
			throws IllegalAccessException, IllegalArgumentException,
			InvocationTargetException {
		if (method.getParameterTypes().length > 0) {
			return null;
		}
		if (method.getName().startsWith("delete")) {
			return null;
		}
		return method.invoke(file);
	}

}
